package cn.harvest.storage.web.servlet;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import cn.harvest.storage.bo.admin.EmploymentService;
import cn.harvest.storage.bo.admin.PermissionService;
import cn.harvest.storage.bo.manager.MerchandiseUnitService;
import cn.sendsms.Service;

public class InitServlet extends HttpServlet {
	
	private Service srv;

	/**
	 * Constructor of the object.
	 */
	public InitServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		// 关闭短信服务
		// try {
		// MessageService messageService = MessageService.getMessageService();
		// messageService.stopService(srv);
		// } catch (Exception e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		super.destroy();
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
		ServletContext servletContext = super.getServletContext();

		// 职务列表
		EmploymentService employmentService = EmploymentService.getService();
		List employmentList = employmentService.selectEmployment();
		servletContext.setAttribute("employmentList", employmentList);
		
		// 权限列表
		PermissionService permissionService = PermissionService.getService();
		List permissionList = permissionService.selectPermission();
		servletContext.setAttribute("permissionList", permissionList);

		// 货品单位列表
		MerchandiseUnitService merchandiseUnitService = MerchandiseUnitService.getService();
		List merchandiseUnitList = merchandiseUnitService.selectMerchandiseUnit();
		servletContext.setAttribute("merchandiseUnitList", merchandiseUnitList);
		
		// 开启短信服务
		// try {
		// MessageService messageService = MessageService.getMessageService();
		// srv = messageService.startService();
		// } catch (Exception e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		// 固定每天 早 8 点 给后天 上课的培训师 发提示短信
		// Timer timer = new Timer();
		// TimerTask smt = new SendMessageTask();
		// timer.schedule(smt, 0, 60 * 1000);// 8点后，每24小时执行一次 24 * 60 * 60 *
		// 1000
	}
}
